package is.model.bean;

import is.NullUtil;
import is.interfaces.Bean;
import is.interfaces.HierarchyBean;
import is.model.exceptions.EmptyValueException;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author aspr0
 */
public class Department extends AbstractHierarchyBean implements Bean, HierarchyBean, Cloneable
{
    private String name;
    private Integer bossId;
    private Integer regionId;

    public Department()
    {
        tableName = "department";
        fields = new String[]
        {
            "name", "parentId", "bossId", "regionId"
        };
    }

    public Integer getBossId()
    {
        return bossId;
    }

    public void setBossId(Integer boss)
    {
        this.bossId = boss;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name) throws EmptyValueException
    {
        this.name = name;
    }

    public Integer getRegionId()
    {
        return regionId;
    }

    public void setRegionId(Integer region)
    {
        this.regionId = region;
    }

    @Override
    public String[] getValues()
    {
        return new String[]
                {
                    NullUtil.toString(name),
                    NullUtil.toString(parentId),
                    NullUtil.toString(bossId),
                    NullUtil.toString(regionId)
                };
    }

    @Override
    public void processResultSet(ResultSet resultSet) throws SQLException
    {
        id = resultSet.getInt(KEY_FIELD);
        name = resultSet.getString(fields[0]);
        parentId = resultSet.getInt(fields[1]);
        bossId = resultSet.getInt(fields[2]);
        regionId = resultSet.getInt(fields[3]);
    }
}
